<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
	<script>
		var img = "img/a.png";//imgurl 就是你的图片路径
		function getBase64Image(imgUrl,callback) {
			var image = new Image();
			image.src = imgUrl;
			console.log(image)
			image.onload = function(){
				var canvas = document.createElement("canvas");
				canvas.width = image.width;
				canvas.height = image.height;
				var ctx = canvas.getContext("2d");
				ctx.drawImage(image, 0, 0, image.width, image.height);
				var ext = image.sr
				c.substring(image.src.lastIndexOf(".")+1).toLowerCase();
				var dataURL = canvas.toDataURL("image/"+ext);
				callback(dataURL);
			}
		}
		getBase64Image(img,(res)=>{
			console.log(res)
		})

	</script>
	</body>
</html>
